package com.easyattendance.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="TBL_SUBJECT")
public class Subject {
	
	@Id
	@Column(name="subject_id",length=6,nullable=false)
	private String subject_id;
	
	@GenericGenerator(name="section_id",strategy="foreign")
	@Column(name="section_id",length=10,nullable=false)
	private String section_id;
	
	/* Many to one mappings of Subject */
	@ManyToOne
	@JoinColumn(name="section_id",insertable=false,updatable=false)
	private Section section;
	
	@ManyToOne
	@JoinColumn(name="class_id")
	private Class classObj;
	
	/*@ManyToOne
	@JoinColumn(name="teacher_id",insertable=false,updatable=false)
	private Teacher teacher;  */
	
	/* One To Many mappings of Subject */
	
	@OneToMany(mappedBy="subject",fetch=FetchType.LAZY)
	@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<SubjectTeacher> subjectTeachers;
	
	@OneToMany(mappedBy="subject",fetch=FetchType.LAZY)
	@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<SubjectClass> subjectClasses;
	
	@OneToMany(mappedBy="subject",fetch=FetchType.LAZY)
	@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<Assignment> assignments;
	
	@OneToMany(mappedBy="subject",fetch=FetchType.LAZY)
	@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<StudentElective> studentElective;
	
	@OneToMany(mappedBy="subject",fetch=FetchType.LAZY)
	@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<MaterialClass> materialClass;
	
	@OneToMany(mappedBy="subject",fetch=FetchType.LAZY)
	@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<TimeTable> timeTable;
	
	@Column(name="subject_name",length=32,nullable=false)
	private String subject_name;
	
	@Column(name="category",length=15)
	private String category;
	

	public Subject() {
		super();
	}
	


	public Subject(String subject_id, Section section, Class classObj,Set<SubjectClass> subjectClasses,
			Set<Assignment> assignments, Set<StudentElective> studentSubject,
			Set<Material> material, Set<TimeTable> timeTable, Set<SubjectTeacher> subjectTeachers,
			String subject_name, String category) {
		super();
		this.subject_id = subject_id;
		this.section = section;
		this.classObj = classObj;
		//this.teacher = teachers;
		this.subjectClasses = subjectClasses;
		this.assignments = assignments;
		this.studentElective = studentElective;
		this.materialClass = materialClass;
		this.timeTable = timeTable;
		this.subjectTeachers = subjectTeachers;
		this.subject_name = subject_name;
		this.category = category;
	}

	public Subject(Section section, Class classObj, String subject_name) {
		super();
		this.section =section;
		this.classObj = classObj;
		this.subject_name = subject_name;
	}

	public Subject(String subject_id, Section section, Class classObj,String subject_name, String category) {
		super();
		this.subject_id = subject_id;
		this.section = section;
		this.classObj = classObj;
		//this.teacher = teacher;
		this.subject_name = subject_name;
		this.category = category;
	}
	
	public Subject(String subject_id, String section_id, String subject_name,
			String category) {
		super();
		this.subject_id = subject_id;
		this.section_id = section_id;
		this.subject_name = subject_name;
		this.category = category;
	}
	
	
	public String getSubject_id() {
		return subject_id;
	}

	public void setSubject_id(String subject_id) {
		this.subject_id = subject_id;
	}

	public String getSection_id() {
		return section_id;
	}

	public void setSection_id(String section_id) {
		this.section_id = section_id;
	}

	public Section getSection() {
		return section;
	}

	public void setSection(Section section) {
		this.section = section;
	}
	
	public Set<SubjectTeacher> getSubjectTeachers() {
		return subjectTeachers;
	}

	public void setSubjectTeachers(Set<SubjectTeacher> subjectTeachers) {
		this.subjectTeachers = subjectTeachers;
	}
	
	public Set<SubjectClass> getSubjectClasses() {
		return subjectClasses;
	}

	public void setSubjectClasses(Set<SubjectClass> subjectClasses) {
		this.subjectClasses = subjectClasses;
	}

	public Set<Assignment> getAssignments() {
		return assignments;
	}

	public void setAssignments(Set<Assignment> assignments) {
		this.assignments = assignments;
	}

	public Set<StudentElective> getStudentElective() {
		return studentElective;
	}

	public void setStudentElective(Set<StudentElective> studentElective) {
		this.studentElective = studentElective;
	}

	
	public Set<MaterialClass> getMaterialClass() {
		return materialClass;
	}

	public void setMaterialClass(Set<MaterialClass> materialClass) {
		this.materialClass = materialClass;
	}

	public Set<TimeTable> getTimeTable() {
		return timeTable;
	}

	public void setTimeTable(Set<TimeTable> timeTable) {
		this.timeTable = timeTable;
	}

	public String getSubject_name() {
		return subject_name;
	}

	public void setSubject_name(String subject_name) {
		this.subject_name = subject_name;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public Class getClassobj() {
		return classObj;
	}

	public void setClassObj(Class classObj) {
		this.classObj = classObj;
	}
	


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((category == null) ? 0 : category.hashCode());
		result = prime * result
				+ ((section == null) ? 0 : section.hashCode());
		result = prime * result + ((classObj == null) ? 0 : classObj.hashCode());
		result = prime * result
				+ ((subject_name == null) ? 0 : subject_name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Subject other = (Subject) obj;
		if (category == null) {
			if (other.category != null) {
				return false;
			}
		} else if (!category.equals(other.category)) {
			return false;
		}
		if (section == null) {
			if (other.section != null) {
				return false;
			}
		} else if (!section.equals(other.section)) {
			return false;
		}
		if (classObj == null) {
			if (other.classObj != null) {
				return false;
			}
		} else if (!classObj.equals(other.classObj)) {
			return false;
		}
		if (subject_name == null) {
			if (other.subject_name != null) {
				return false;
			}
		} else if (!subject_name.equals(other.subject_name)) {
			return false;
		}
		return true;
	}

}
